package cn.group7.padserver.controller;

import cn.group7.padserver.common.Flag;
import cn.group7.padserver.controller.responseformat.Code;
import cn.group7.padserver.controller.responseformat.Result;
import cn.group7.padserver.entity.Page;
import cn.group7.padserver.pojo.BankUser;
import cn.group7.padserver.pojo.Finance;
import cn.group7.padserver.service.FinanceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 谷汉斌
 * @description
 * @createTime 2024/8/4 下午11:58
 */
@RestController
@RequestMapping("/bankfinances")
public class BankFinanceController {

    @Autowired
    private FinanceService financeService;

    private Integer bankid;

    //查询推荐融资人
    @ApiOperation(value = "分页查询推荐融资人")
    @GetMapping("/selectRecommend")
    public Result selectRecommend(@RequestParam("pageNum") Integer pageNum, @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        Page<BankUser> list = financeService.selectRecommend(pageNum, pageSize);
        return Result.builder().flag(Flag.SUCCESS.isCode())
                .code(Code.QUERY_SUCCESS.getCode())
                .message(Code.QUERY_SUCCESS.getInfo())
                .data(list).build();
    }

    //根据id修改融资情报
    @ApiOperation(value = "根据id修改融资情报")
    @PutMapping("/update")
    public Result update(@RequestBody Finance finance) {
        financeService.updateByFinance(finance);
        return Result.builder().flag(Flag.SUCCESS.isCode()).code(Code.QUERY_SUCCESS.getCode())
                .message(Code.UPDATE_SUCCESS.getInfo()).build();
    }

    //根据id查询融资情报
    @ApiOperation(value = "根据id查询融资情报")
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable("id") Integer id) {
        Finance finance = financeService.selectByFinanceId(id);
        return Result.builder().flag(Flag.SUCCESS.isCode()).code(Code.QUERY_SUCCESS.getCode())
                .message(Code.QUERY_SUCCESS.getInfo())
                .data(finance).build();
    }
}
